package com.jia.leetCode;

import java.util.Arrays;

/**
 * @program: Leetcode
 * @description:
 * @author: STU756
 * @create: 2020-08-24 12:42
 */
public class Pro1558 {
    //不妨反过来，求解nums变为全零所需的最小步数
    public int minOperations(int[] nums) {
        Arrays.sort(nums);
        int count = 0;
        while(nums[nums.length - 1] != 0) {
            for(int i = 0; i < nums.length; i++) {
                if(nums[i] % 2 == 1) {
                    nums[i] -= 1;

                    ++count;
                }
            }
            if(nums[nums.length - 1] == 0) return count;
            for(int i = 0; i < nums.length; i++) {
                nums[i] /= 2;
            }
            ++count;
        }
        return count;
    }
}
